<?php
namespace app\common\util;

class Password
{
    // 生成16字节的盐值，并转换为十六进制字符串
    public static function gen_salt(){
        try {
            return bin2hex(random_bytes(4));
        } catch (\Exception $e) {
            return false;
        }
    }
    public static function gen_pass_hash($password,$salt=''){
        return  hash('sha256', $salt . $password);
    }
    public static function verify_password($password, $storedHash, $salt) {
        $passwordHash = self::gen_pass_hash($password,$salt);
        return hash_equals($storedHash, $passwordHash);
    }
}